//
//  SMHOrderCell.swift
//  SMHCommerce
//
//  Created by lvzhao on 2020/6/4.
//  Copyright © 2020 lvzhao. All rights reserved.
//

import UIKit
import ReactiveCocoa

class SMHOrderCell: LZBaseTableViewCell {

    var oderNumLab :UILabel?  //订单号
    var statueLab :UILabel?  //状态
    var produceNameLab :UILabel?  //商品名字
    var merchantNameLab :UILabel?  //商户名字
    var paymentNumLab :UILabel?  //付款金额

    var payBtn :UIButton?  //立即支付
    var receiveBtn :UIButton?  //确认收货
    var deliveryBtn :UIButton?  //确认发货
    var expressyBtn :UIButton?  //物流
    var lateDeliveryBtn :UIButton?  //延时发送
    var subDeliveryBtn :UIButton?  //一键代发

    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = UIColorFromHex(rgbValue: 0xF2F2F2)

        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK:setupUI
    func setupUI() {
    
        let contenView = UIView.init(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 152))
        contenView.backgroundColor = .white
        addSubview(contenView)
        
        //订单
        oderNumLab = UILabel()
        oderNumLab!.text = "订单号:"
        oderNumLab!.font = ktextFont(size: 12)
        oderNumLab!.textColor = UIColorFromHex(rgbValue: 0x363636)
        addSubview(self.oderNumLab!)
        oderNumLab!.snp.makeConstraints { (make) in
            make.left.top.equalTo(15)
            make.height.equalTo(12)
            make.width.equalTo(230)
        }

        
        
        //状态
        statueLab = UILabel()
        statueLab?.textAlignment = .right
        statueLab!.font = ktextFont(size: 12)
        statueLab!.textColor = UIColorFromHex(rgbValue: 0x363636)
        addSubview(self.statueLab!)
        statueLab!.snp.makeConstraints { (make) in
            make.right.equalTo(-15)
            make.top.equalTo(15)
            make.height.equalTo(12)
            make.width.equalTo(80)
        }
        
        let lineTopView = UIView()
        lineTopView.backgroundColor = UIColorFromHex(rgbValue: 0xF2F2F2)
        addSubview(lineTopView)
        lineTopView.snp.makeConstraints { (make) in
            make.right.equalTo(-15)
            make.left.equalTo(15)
            make.height.equalTo(0.5)
            make.top.equalTo(self.oderNumLab!.snp.bottom).offset(13)
        }
  
        //商品
        let produceLab = UILabel()
        produceLab.text = "商品:"
        produceLab.font = ktextFont(size: 14)
        produceLab.textColor = UIColorFromHex(rgbValue: 0x363636)
        addSubview(produceLab)
        produceLab.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.top.equalTo(lineTopView.snp.bottom).offset(15)
            make.height.equalTo(15)
            make.width.equalTo(35)
        }

        produceNameLab = UILabel()
        produceNameLab!.textColor = UIColorFromHex(rgbValue: 0x363636)
        produceNameLab!.font = ktextFont(size: 14)
        addSubview(produceNameLab!)
        produceNameLab!.snp.makeConstraints { (make) in
            make.left.equalTo(produceLab.snp.right)
            make.centerY.equalTo(produceLab.snp.centerY)
            make.height.equalTo(15)
            make.right.equalTo(-15)
        }
        
        
        //商户
        let merchantLab = UILabel()
        merchantLab.text = "商户:"
        merchantLab.font = ktextFont(size: 14)
        merchantLab.textColor = UIColorFromHex(rgbValue: 0x363636)
        addSubview(merchantLab)
        merchantLab.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.top.equalTo(produceLab.snp.bottom).offset(10)
            make.height.equalTo(15)
            make.width.equalTo(35)
        }

        merchantNameLab = UILabel()
        merchantNameLab!.textColor = UIColorFromHex(rgbValue: 0x363636)
        merchantNameLab!.font = ktextFont(size: 14)
        addSubview(merchantNameLab!)
        merchantNameLab!.snp.makeConstraints { (make) in
            make.left.equalTo(merchantLab.snp.right)
            make.centerY.equalTo(merchantLab)
            make.height.equalTo(15)
            make.right.equalTo(-15)
        }
        
        let lineBottomView = UIView()
        lineBottomView.backgroundColor = UIColorFromHex(rgbValue: 0xF2F2F2)
        addSubview(lineBottomView)
        lineBottomView.snp.makeConstraints { (make) in
            make.right.equalTo(-15)
            make.left.equalTo(15)
            make.height.equalTo(0.5)
            make.top.equalTo(108)
        }
        
        //付款金额
        let paymentLab = UILabel()
        paymentLab.text = "付款金额:"
        paymentLab.textColor = UIColorFromHex(rgbValue: 0x363636)
        paymentLab.font = ktextFont(size: 14)
        addSubview(paymentLab)
        paymentLab.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.width.equalTo(70)
            make.height.equalTo(15)
            make.top.equalTo(lineBottomView.snp.bottom).offset(15)
        }
        
        paymentNumLab = UILabel()
        paymentNumLab!.textColor = UIColorFromHex(rgbValue: 0xFF661B)
        paymentNumLab!.font = ktextFont(size: 14)
        addSubview(paymentNumLab!)
        paymentNumLab!.snp.makeConstraints { (make) in
            make.left.equalTo(paymentLab.snp.right)
            make.width.equalTo(150)
            make.height.equalTo(15)
            make.centerY.equalTo(paymentLab.snp.centerY)
        }
        
        
        let btnw = 60
        //MARK:按钮
        payBtn = UIButton.init(type: .custom)
        payBtn!.setTitle("立即支付", for: .normal)
        payBtn!.titleLabel?.font = ktextFont(size: 12)
        payBtn!.setTitleColor(UIColor.white, for: .normal)
        addSubview(payBtn!)
        payBtn!.titleLabel?.adjustsFontSizeToFitWidth = true
        payBtn!.snp.makeConstraints { (make) in
            make.right.equalTo(-15)
            make.centerY.equalTo(paymentLab)
            make.height.equalTo(27)
            make.width.equalTo(btnw)
        }
        payBtn!.isHidden = true
        payBtn!.layoutViewGradient(style: .ViewGradientStyleLeft, colors: nil)
        payBtn!.clipRectCorner(direction: .allCorners, cornerRadius: 13.5)
        
        
        //确认收货
        receiveBtn = UIButton.init(type: .custom)
        receiveBtn!.setTitle("确认收货", for: .normal)
        receiveBtn!.titleLabel?.font = ktextFont(size: 12)
        receiveBtn!.setTitleColor(UIColor.white, for: .normal)
        addSubview(receiveBtn!)
        receiveBtn!.titleLabel?.adjustsFontSizeToFitWidth = true
        receiveBtn!.snp.makeConstraints { (make) in
            make.right.equalTo(-15)
            make.centerY.equalTo(paymentLab)
            make.height.equalTo(27)
            make.width.equalTo(btnw)
        }
        receiveBtn!.isHidden = true
        receiveBtn!.layoutViewGradient(style: .ViewGradientStyleLeft, colors: nil)
        receiveBtn!.clipRectCorner(direction: .allCorners, cornerRadius: 13.5)


        deliveryBtn = UIButton.init(type: .custom)
        deliveryBtn!.setTitle("确认发货", for: .normal)
        deliveryBtn!.titleLabel?.font = ktextFont(size: 12)
        deliveryBtn!.setTitleColor(UIColor.white, for: .normal)
        addSubview(deliveryBtn!)
        deliveryBtn!.titleLabel?.adjustsFontSizeToFitWidth = true
        deliveryBtn!.snp.makeConstraints { (make) in
            make.right.equalTo(-15)
            make.centerY.equalTo(paymentLab)
            make.height.equalTo(27)
            make.width.equalTo(btnw)
        }
        deliveryBtn!.isHidden = !true
        deliveryBtn!.layoutViewGradient(style: .ViewGradientStyleLeft, colors: nil)
        deliveryBtn!.clipRectCorner(direction: .allCorners, cornerRadius: 13.5)
        
        
        expressyBtn = UIButton.init(type: .custom)
        expressyBtn!.setTitle("查看物流", for: .normal)
        expressyBtn!.titleLabel?.font = ktextFont(size: 12)
        expressyBtn!.setTitleColor(UIColorFromHex(rgbValue: 0x363636), for: .normal)
        addSubview(expressyBtn!)
        expressyBtn!.titleLabel?.adjustsFontSizeToFitWidth = true
        expressyBtn!.snp.makeConstraints { (make) in
            make.right.equalTo(-80)
            make.centerY.equalTo(paymentLab)
            make.height.equalTo(27)
            make.width.equalTo(btnw)
        }
        expressyBtn!.isHidden = true
        expressyBtn!.cornerRadius(cornerRadius: 13.5)
        expressyBtn!.borderColor(color: UIColorFromHex(rgbValue: 0x363636))
        expressyBtn!.borderWidth(width: 0.5)
        
        
        lateDeliveryBtn = UIButton.init(type: .custom)
        lateDeliveryBtn!.setTitle("延时发送", for: .normal)
        lateDeliveryBtn!.titleLabel?.font = ktextFont(size: 12)
        lateDeliveryBtn!.setTitleColor(UIColor.white, for: .normal)
        addSubview(lateDeliveryBtn!)
        lateDeliveryBtn!.titleLabel?.adjustsFontSizeToFitWidth = true
        lateDeliveryBtn!.snp.makeConstraints { (make) in
            make.right.equalTo(-80)
            make.centerY.equalTo(paymentLab)
            make.height.equalTo(27)
            make.width.equalTo(btnw)
        }
        lateDeliveryBtn!.isHidden = !true
        lateDeliveryBtn!.layoutViewGradient(style: .ViewGradientStyleLeft, colors: nil)
        lateDeliveryBtn!.clipRectCorner(direction: .allCorners, cornerRadius: 13.5)
        
        
        subDeliveryBtn = UIButton.init(type: .custom)
        subDeliveryBtn!.setTitle("一键代发", for: .normal)
        subDeliveryBtn!.titleLabel?.font = ktextFont(size: 12)
        subDeliveryBtn!.setTitleColor(UIColor.white, for: .normal)
        addSubview(subDeliveryBtn!)
        subDeliveryBtn!.titleLabel?.adjustsFontSizeToFitWidth = true
        subDeliveryBtn!.snp.makeConstraints { (make) in
            make.right.equalTo( -25-120)
            make.centerY.equalTo(paymentLab)
            make.height.equalTo(27)
            make.width.equalTo(btnw)
        }
        subDeliveryBtn!.isHidden = !true
        subDeliveryBtn!.layoutViewGradient(style: .ViewGradientStyleLeft, colors: nil)
        subDeliveryBtn!.clipRectCorner(direction: .allCorners, cornerRadius: 13.5)
        
        
        
        
        /*
        var receiveBtn :UIButton?  //确认收货
        var deliveryBtn :UIButton?  //确认发货
        var expressyBtn :UIButton?  //物流
        var lateDeliveryBtn :UIButton?  //延时发送
        var subDeliveryBtn :UIButton?  //一键代发
        */
        
        
        
        payBtn!.reactive.controlEvents(.touchUpInside).observeResult { (button) in
            print("立即支付")
        }


        receiveBtn!.reactive.controlEvents(.touchUpInside).observeResult { (button) in
            print("确认收货")
        }

        deliveryBtn!.reactive.controlEvents(.touchUpInside).observeResult { (button) in
            print("确认发货")
        }
        
        expressyBtn!.reactive.controlEvents(.touchUpInside).observeResult { (button) in
            print("查看物流")
        }
        
        lateDeliveryBtn!.reactive.controlEvents(.touchUpInside).observeResult { (button) in
            print("延时发送")
        }
        
        subDeliveryBtn!.reactive.controlEvents(.touchUpInside).observeResult { (button) in
            print("一键代发")
        }
        
    }
    var modelObject : AnyObject?{
        didSet {
            self.oderNumLab!.text = "订单号:123545789012354578900123545789000"
            self.statueLab!.text = "待付款"
            self.produceNameLab!.text = "沙嗲水电卡开始的卡双击打开氨基酸看得见啊数据库"
            self.merchantNameLab!.text = "18494972322"
            self.paymentNumLab!.text = "¥ 90.00"

        }
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
